﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace BubbleSurvival
{
    /// <summary>
    /// 2D-s kamera
    /// <para>pozíció</para>
    /// <para>zoom</para>
    /// </summary>
    public class Camera
    {
        protected float zoom;       // zoom érétk
        public Matrix transform;    // Draw-hoz szükséges transzformálás
        private Vector2 pos;        // pozíció
        
        const float DEFZOOM = 1.0f;
        const float MINZOOM = 0.1f;

        // Konstruktor
        public Camera()
        {
            zoom = DEFZOOM;
            pos = Vector2.Zero;
        }

        public float Zoom
        {
            get { return zoom; }
            set { zoom = value; if (zoom < MINZOOM) zoom = MINZOOM; }
        }

        /// <summary>
        /// A camera pos-t eltolja egy Vector2-vel
        /// </summary>
        public void Move(Vector2 amount)
        {
            pos += amount;
        }

        public Vector2 Pos
        {
            get { return pos; }
            set { pos = value; }
        }

        /// <summary>
        /// A Draw-hoz szükséges mtx-transzf.
        /// </summary>
        public Matrix CreateTransformatedMatrix(GraphicsDevice graphicsDevice)
        {
            return
                Matrix.CreateScale(zoom) *
                Matrix.CreateTranslation(
                    (graphicsDevice.Viewport.Width * 0.5f) - (pos.X * zoom),
                    (graphicsDevice.Viewport.Height * 0.5f) - (pos.Y * zoom),
                    0);
        }

    }

}
